import * as types from './mutation-types'
import {STORAGE_TYPE} from '../common/js/config'

const mutations = {
  [types.SET_TEMP_QUERY](state, o) {
    state.tempQuery = o
  },
  [types.SET_USER_INFO](state, o) {
    // o为用户登录信息，传o时登录，不传时退出登录
    /*
    * {
    *   // 登录信息格式
    *   status: 1,
    *   role: 'user'
    * }
    * */
    if (o) {
      state.userInfo = o
      state.role = o.role || 'user'
      localStorage.setItem(STORAGE_TYPE.userInfo, JSON.stringify(o))
    } else {
      state.userInfo = null
      localStorage.removeItem(STORAGE_TYPE.userInfo)
      sessionStorage.clear()
    }
  },
  [types.SET_ORDER](state, o) {
    state.order = o
  },
  [types.SET_BOOK](state, o) {
    state.book = o
  },
  [types.SET_CORP_QUERY](state, o) {
    state.corpQuery = o
  }
}

export default mutations
